package bit1;
import java.util.*;
public class Main554 {
    public static void main(String[] args) {
        int[] pushA={1,2,3,4,5};
        int[] popA={4,3,5,1,2};
        Stack<Integer> stack=new Stack<>();
        int count=0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            if(!stack.isEmpty()&&stack.peek()==popA[count]){
                stack.pop();
                count++;
            }
        }
        if(stack.isEmpty()){
            System.out.println(true);
        }
    }
    public static void main2(String[] args) {
        String s = "ab#c";
        String t = "ad#c";
        char ch1[] = s.toCharArray();
        char ch2[] = t.toCharArray();
        Stack<Character> stack1 = new Stack();
        Stack<Character> stack2 = new Stack();
        for (char ch : ch1) {
            if(ch=='#'){
                if(!stack1.empty()){
                    stack1.pop();
                }
            }
            else {
                stack1.push(ch);
            }
        }
        for (char ch : ch2) {
            if(ch=='#'){
                if(!stack2.empty()){
                    stack2.pop();
                }
            }
            else {
                stack2.push(ch);
            }
        }
        s = "";
        t = "";
        while (!stack1.isEmpty()&&!stack2.isEmpty()) {
            s += stack1.pop();
            t += stack2.pop();
        }
        if (!stack1.isEmpty()||!stack2.isEmpty()){
            System.out.println(false);
        }
        if (s.equals(t)){
            System.out.println(true);
        }
        else {
            System.out.println(false);
        }
    }
    public static void main1(String[] args) {
        String str[]={"5","-2","4","C","D","9","+","+"};
        int num1,num;
        Stack<Integer> stack=new Stack<>();
        for (String s:str) {
            if ("+".equals(s)) {

                num1 = stack.pop();
                num = num1 + stack.peek();
                stack.push(num1);
                stack.push(num);
            } else if ("D".equals(s)) {

                num = stack.peek() * 2;
                stack.push(num);
            } else if ("C".equals(s)) {

                stack.pop();
            } else {

                stack.push(Integer.valueOf(s));
            }
        }
        int sum=0;
        while (!stack.empty()){
            sum+=stack.pop();
        }
        System.out.println(sum);
    }
}
